package C014;

import java.util.LinkedList;
import java.util.Queue;

/**
 * ClassName: QueueImpleStack
 * Package: C014
 * Description:
 *
 * @Author BCXJ
 * @Create 2024/12/3 15:56
 * @Version 1.0
 * @Since 1.0
 */
public class QueueImpleStack {
    public static void main(String[] args) {
        MyStack myStack = new MyStack();
        myStack.push(1);
        myStack.push(2);
        System.out.println(myStack.top()); // 返回 2
        System.out.println(myStack.pop()); // 返回 2
        System.out.println(myStack.empty()); // 返回 False
    }
    static class MyStack {
        Queue<Integer> queue = new LinkedList<>();
        public MyStack() {

        }

        public void push(int x) {
            int size = queue.size();
            queue.offer(x);
            for (int i = 0; i < size; i++) {
                queue.offer(queue.poll());
            }
        }

        public int pop() {
            return queue.poll();
        }

        public int top() {
            return queue.peek();
        }

        public boolean empty() {
            return queue.isEmpty();
        }
    }

    /**
     * Your MyStack object will be instantiated and called as such:
     * MyStack obj = new MyStack();
     * obj.push(x);
     * int param_2 = obj.pop();
     * int param_3 = obj.top();
     * boolean param_4 = obj.empty();
     */
}
